package com.kool.kreport.common.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author luyu
 */
public class MsgdgtUtil {
    /**
     * 生成签名
     * msgdgt = md5(appSecret + appid + ts + 所有参数按key排序(key + value))
     *
     * @return
     */
    public static String createMsgdgt(String appSecret, String appid, String ts, Map<String, String> params) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(appSecret);
        stringBuffer.append(appid);
        stringBuffer.append(ts);

        List<String> keys = new ArrayList(params.keySet());
        //排序
        Collections.sort(keys);
        //拼接
        for (String key : keys) {
            stringBuffer.append(key + params.get(key));
        }
        //MD5
        String msgdgtC = SecurityUtil.md5(stringBuffer.toString()).toUpperCase();

        return msgdgtC;
    }

}
